procedure WriteChunkString(Code: TPhChunkCode; const s: String); // Auto-detecting type
// -- Reads chunk code and datatype
function ReadChunk(out Code: TPhChunkCode; out Datatype: TPhChunkDatatype): TPhReadingChunkResult;
// -- Reads chunk code, datatype and value. Value is being read only if result is not rcrInvalidDatatype or rcrEOF,
// invalid datatype raises exception. bSkipUnknown controls whether to skip unknown chunks (including all nested,
// if necessary). bSkipUnmatched controls whether to skip chunks which datatype mismatches from predefined one
function ReadChunkValue(out Code: TPhChunkCode; out Datatype: TPhChunkDatatype; var vValue: Variant; bSkipUnknown, bSkipUnmatched: Boolean): TPhReadingChunkResult;
// Skips all chunks until close-chunk for OpenCode chunk code encountered. May be used for ignoring unknown
// open-chunks. It is valid to call SkipNestedChunks for non-open-chunks (ignored if it's the case)
function TPhoaStreamer.ReadChunk(out Code: TPhChunkCode; out Datatype: TPhChunkDatatype): TPhReadingChunkResult;
var pe: PPhChunkEntry;
begin
try
// Check if there are data at all
if FStream.Position>=FStream.Size then begin
Code := 0;
Datatype := pcdEmpty;
Result := rcrEOF;
// Read the chunk and its datatype
end else begin
Code := ReadWord;
Datatype := TPhChunkDatatype(ReadByte);
// Try to find a chunk
pe := FindChunk(Code);
// Validate Datatype
if not (Datatype in [Low(Datatype)..High(Datatype)]) then Result := rcrInvalidDatatype
// If not found
else if pe=nil then Result := rcrUnknown
// Compare Datatype
else if Datatype<>pe.Datatype then Result := rcrDatatypeMismatch
// Ok
else Result := rcrOK;
end;
except
FErrorsOccured := True;
raise;
end;
end;
function TPhoaStreamer.ReadChunkValue(out Code: TPhChunkCode; out Datatype: TPhChunkDatatype; var vValue: Variant; bSkipUnknown, bSkipUnmatched: Boolean): TPhReadingChunkResult;